package com.liner.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liner.vo.SellerOrderMasterVo;
import com.liner.entity.OrderMaster;
import com.liner.result.Result;
import com.liner.service.OrderDetailService;
import com.liner.service.OrderMasterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author liner
 * @since 2022-12-03
 */
@RestController
@RequestMapping("/seller/order")
@Api(tags = "卖家端订单接口", description = "卖家端 商品订单接口")
public class SellerOrderController {

    @Autowired
    private OrderMasterService orderMasterService;

    @Autowired
    private OrderDetailService orderDetailService;

    @ApiOperation("查询订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数"),
            @ApiImplicitParam(name = "size", value = "每页条数")
    })
    @GetMapping("/list/{page}/{size}")
    public Result list(@PathVariable Integer page, @PathVariable Integer size) {

        Page<OrderMaster> orderMasterPage = new Page<>(page, size);
        Page<OrderMaster> resultPage = orderMasterService.page(orderMasterPage);
        SellerOrderMasterVo vo = new SellerOrderMasterVo();
        vo.setContent(resultPage.getRecords());
        vo.setPage(resultPage.getPages());
        vo.setTotal(resultPage.getTotal());
        return Result.ok(vo);
    }


    @ApiOperation("取消订单")
    @ApiImplicitParam(name = "orderId", value = "订单ID")
    @PutMapping("/cancel/{orderId}")
    public Result cancel(@PathVariable("orderId") String orderId) {
        orderMasterService.cancel(null, orderId);
        return Result.ok();
    }

    @ApiOperation("完结订单")
    @ApiImplicitParam(name = "orderId", value = "订单ID")
    @PutMapping("/finish/{orderId}")
    public Result finish(@PathVariable("orderId") String orderId) {
        orderMasterService.finish(orderId);
        return Result.ok();
    }

    @ApiOperation("柱状图")
    @PutMapping("/barSale")
    public Result barSale() {
        return Result.ok(orderDetailService.barData());
    }

    @ApiOperation("基础折线图")
    @PutMapping("/basicLineSale")
    public Result basicLineSale() {
        return Result.ok(orderDetailService.basicLineData());
    }

    @ApiOperation("折线图堆叠")
    @PutMapping("/stackedLineSale")
    public Result stackedLineSale() {
        return Result.ok(orderDetailService.stackedLineData());
    }


}

